*Replication files for Barrie, Clarke, and Ketchley "Burnings, Beatings, and Bombings:
*Disaggregating Anti-Christian Violence in Egypt, 2013-2018"

set more off
clear

*log file
log using "C:\Users\neilke\Dropbox\sectarian_paper\production\replication_files\analysis_log.log", replace

*set your command directory
cap cd "C:\Users\neilke\Dropbox\sectarian_paper\production\replication_files\data\final\"

*read in district day dataset
cap use "barrie_clarke_ketchley_dataset", clear

*install packages
*ssc install vce2way
*net install spost13_ado.pkg

********************************************************************************
*Macros
********************************************************************************

*DV
global basic_dv dv_burning_beating_bombing

*Controls
global controls log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density lprevious_attack

*H1
global h1 mboccup pct_mursi_2012 c.pct_shafiq_2012##c.pct_shafiq_2012 rabaa sqrt_killed_at_rabaa

*H2
global h2 CPI_pct public_holiday_christian public_holiday_muslim friday sqrt_co_ethnic

*H3
global h3 sqrt_distance_from_north_sinai sqrt_distance_to_gov_centre

*H4
global h4 sqrt_police_strikes


********************************************************************************
*Table 1 - Predicting the incidence of burnings, beatings, and bombings
********************************************************************************

*Model 1
vce2way mlogit $basic_dv $h1 $controls, cluster(gov_ID adm2_pcode)
mlogit, rrr

*Model 2
vce2way mlogit $basic_dv $h1 $h2 $controls, cluster(gov_ID adm2_pcode)
mlogit, rrr

*Model 3
vce2way mlogit $basic_dv $h1 $h2 $h3 $controls, cluster(gov_ID adm2_pcode)
mlogit, rrr

*Model 4
vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode)
mlogit, rrr

********************************************************************************
*Figure 4 - Marginal effects plot
********************************************************************************	
	
*Figure 4A - Christians (logged)
margins, at(log10christians=(1(1)5)) pr(out(2)) pr(out(3)) pr(out(4)) level(90)

marginsplot, recast(line) recastci(rarea) plot1opts(lcolor(red) lpattern("--")) plot2opts(lcolor(green) lpattern(longdash)) plot3opts(lcolor(blue) lpattern(shortdash dot)) ///
	ci1opts(color(red%15) lwidth(none)) ci2opts(color(green%15) lwidth(none)) ci3opts(color(blue%15) lwidth(none)) ///
	xlabel(1 "10" 2 "100" 3 "1000" 4 "10000" 5 "100000") xtitle("Christians") ///
	ytitle("Pr(Event type)") ///
	legend(order(4 "Burning" 5 "Beating" 6 "Bombing") ring(0) position(10) bmargin(medlarge)) ///
	aspectratio(1) ///
	title("")

*Figure 4B - Churches (sqrt.)
margins, at(sqrt_coptic_churches=(0(1)7)) pr(out(2)) pr(out(3)) pr(out(4)) level(90)

marginsplot, recast(line) recastci(rarea) plot1opts(lcolor(red) lpattern("--")) plot2opts(lcolor(green) lpattern(longdash)) plot3opts(lcolor(blue) lpattern(shortdash dot)) ///
	ci1opts(color(red%15) lwidth(none)) ci2opts(color(green%15) lwidth(none)) ci3opts(color(blue%15) lwidth(none)) ///
	xtitle("Churches (sqrt)") ///
	ytitle("Pr(Event type)") ///
	aspectratio(1) ///
	legend(off) ///
	title("")	
	
*Figure 4C - Mursi pct.
margins, at(pct_mursi_2012=(0(10)60)) pr(out(2)) pr(out(3)) pr(out(4)) level(90)

marginsplot, recast(line) recastci(rarea) plot1opts(lcolor(red) lpattern("--")) plot2opts(lcolor(green) lpattern(longdash)) plot3opts(lcolor(blue) lpattern(shortdash dot)) ///
	ci1opts(color(red%15) lwidth(none)) ci2opts(color(green%15) lwidth(none)) ci3opts(color(blue%15) lwidth(none)) ///
	xtitle("Mursi (%)") ///
	ytitle("Pr(Event type)") ///
	legend(off) ///
	aspectratio(1) ///
	title("")	
	
*Figure 4D - CPI	
margins, at(CPI_pct=(-5(10)95)) pr(out(2)) pr(out(3)) pr(out(4)) level(90)

marginsplot, recast(line) recastci(rarea) plot1opts(lcolor(red) lpattern("--")) plot2opts(lcolor(green) lpattern(longdash)) plot3opts(lcolor(blue) lpattern(shortdash dot)) ///
	ci1opts(color(red%15) lwidth(none)) ci2opts(color(green%15) lwidth(none)) ci3opts(color(blue%15) lwidth(none)) ///
	xtitle("CPI") ///
	ytitle("Pr(Event type)") ///
	xlabel(-5 15 35 55 75 95) ///
	legend(off) ///
	aspectratio(1) ///
	title("")
	
*Figure 4E - Dist. N. Sinai (sqrt.)
margins, at(sqrt_distance_from_north_sinai=(5(5)30)) pr(out(2)) pr(out(3)) pr(out(4)) level(90)

marginsplot, recast(line) recastci(rarea) plot1opts(lcolor(red) lpattern("--")) plot2opts(lcolor(green) lpattern(longdash)) plot3opts(lcolor(blue) lpattern(shortdash dot)) ///
	ci1opts(color(red%15) lwidth(none)) ci2opts(color(green%15) lwidth(none)) ci3opts(color(blue%15) lwidth(none)) ///
	xtitle("Distance to N. Sinai (sqrt)") ///
	ytitle("Pr(Event type)") ///
	legend(off) ///
	aspectratio(1) ///
	title("")
	
*Figure 4F - Dist. Gov. centre (sqrt.)
margins, at(sqrt_distance_to_gov_centre=(0(5)20)) pr(out(2)) pr(out(3)) pr(out(4)) level(90)

marginsplot, recast(line) recastci(rarea) plot1opts(lcolor(red) lpattern("--")) plot2opts(lcolor(green) lpattern(longdash)) plot3opts(lcolor(blue) lpattern(shortdash dot)) ///
	ci1opts(color(red%15) lwidth(none)) ci2opts(color(green%15) lwidth(none)) ci3opts(color(blue%15) lwidth(none)) ///
	xtitle("Distance to gov (sqrt)") ///
	ytitle("Pr(Event type)") ///
	legend(off) ///
	aspectratio(1) ///
	title("")

*Figure 4G Police strikes (sqrt.)
margins, at(sqrt_police_strikes=(0(1)3)) pr(out(2)) pr(out(3)) pr(out(4)) level(90)
	
marginsplot, recast(line) recastci(rarea) plot1opts(lcolor(red) lpattern("--")) plot2opts(lcolor(green) lpattern(longdash)) plot3opts(lcolor(blue) lpattern(shortdash dot)) ///
	ci1opts(color(red%15) lwidth(none)) ci2opts(color(green%15) lwidth(none)) ci3opts(color(blue%15) lwidth(none)) ///
	xtitle("Police strikes (sqrt)") ///
	ytitle("Pr(Event type)") ///
	aspectratio(1) ///
	legend(off) ///
	title("")	
	

********************************************************************************
*Appendix Figure A1 - Link plot
********************************************************************************

*Add factor markers to globals
*Controls
global controls_link log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density i.lprevious_attack

*H1
global h1_link i.mboccup pct_mursi_2012 pct_shafiq_2012 shafiq_sq i.rabaa sqrt_killed_at_rabaa

*H2
global h2_link CPI_pct i.public_holiday_christian i.public_holiday_muslim i.friday sqrt_co_ethnic

*H3
global h3_link sqrt_distance_from_north_sinai sqrt_distance_to_gov_centre

*H4
global h4_link sqrt_police_strikes

vce2way mlogit $basic_dv $h1_link $h2_link $h3_link $h4_link $controls_link, cluster(gov_ID adm2_pcode)

*retaining variable ordering
local varlist mboccup pct_mursi_2012 pct_shafiq_2012 shafiq_sq rabaa sqrt_killed_at_rabaa CPI_pct public_holiday_christian public_holiday_muslim friday sqrt_co_ethnic sqrt_distance_from_north_sinai sqrt_distance_to_gov_centre sqrt_police_strikes log10christians sqrt_coptic_churches agriculture_pct university_pct ln_population_density lprevious_attack


foreach v of var `varlist' {
	local i = `i' + 1
	mlogitplot `v', symbols(No Bu Be Bo) linepvalues(.01) scale(.5) ///
	varlabels mcolors(black red green blue) lcolor(black%75) ///
	plotregion(lcolor(black) margin(l=5 r=5)) linegapfactor(2) ///
	titlebottom(" ")  sdlabel(" ") msizefactor(2) ///
	graphoptions(lpattern(shortdash) lwidth(medthick)) name(g`i', replace)
	gr_edit yaxis1.style.editstyle majorstyle(tickangle(vertical)) editcopy
	gr_edit yaxis1.style.editstyle majorstyle(tickstyle(textstyle(size(huge)))) editcopy
	gr_edit plotregion2._xylines[1].style.editstyle linestyle(width(none)) editcopy
	gr_edit xaxis2.title.text = {}
	gr_edit xaxis2.title.style.editstyle size(large) editcopy 
	local graphs "`graphs' g`i'"
}
graph combine `graphs', cols(5) graphregion(margin(l=0 r=1)) imargin(0 0 0) ysize(4) ///
caption("Note: No = no event; Bu = Burning; Be = Beating; Bo = Bombing", size(tiny))
gr_edit plotregion1.graph1.xaxis2.title.text = {}
gr_edit plotregion1.graph1.xaxis2.title.text.Arrpush Odds Ratio Relative to Category "No"
gr_edit plotregion1.graph2.xaxis2.title.text = {}
gr_edit plotregion1.graph2.xaxis2.title.text.Arrpush Odds Ratio Relative to Category "No"
gr_edit plotregion1.graph3.xaxis2.title.text = {}
gr_edit plotregion1.graph3.xaxis2.title.text.Arrpush Odds Ratio Relative to Category "No"
gr_edit plotregion1.graph4.xaxis2.title.text = {}
gr_edit plotregion1.graph4.xaxis2.title.text.Arrpush Odds Ratio Relative to Category "No"
gr_edit plotregion1.graph5.xaxis2.title.text = {}
gr_edit plotregion1.graph5.xaxis2.title.text.Arrpush Odds Ratio Relative to Category "No"
gr_edit plotregion1.graph16.xaxis1.title.style.editstyle size(large) editcopy
gr_edit plotregion1.graph16.xaxis1.title.text = {}
gr_edit plotregion1.graph16.xaxis1.title.text.Arrpush Logit Coefficient Relative to Category "No"
gr_edit plotregion1.graph17.xaxis1.title.style.editstyle size(large) editcopy
gr_edit plotregion1.graph17.xaxis1.title.text = {}
gr_edit plotregion1.graph17.xaxis1.title.text.Arrpush Logit Coefficient Relative to Category "No"
gr_edit plotregion1.graph18.xaxis1.title.style.editstyle size(large) editcopy
gr_edit plotregion1.graph18.xaxis1.title.text = {}
gr_edit plotregion1.graph18.xaxis1.title.text.Arrpush Logit Coefficient Relative to Category "No"
gr_edit plotregion1.graph19.xaxis1.title.style.editstyle size(large) editcopy
gr_edit plotregion1.graph19.xaxis1.title.text = {}
gr_edit plotregion1.graph19.xaxis1.title.text.Arrpush Logit Coefficient Relative to Category "No"
gr_edit plotregion1.graph20.xaxis1.title.style.editstyle size(large) editcopy
gr_edit plotregion1.graph20.xaxis1.title.text = {}
gr_edit plotregion1.graph20.xaxis1.title.text.Arrpush Logit Coefficient Relative to Category "No"


	
********************************************************************************
*Appendix Table B1 - Dropping smallest and largest predicted probabilities 
********************************************************************************

egen pattern = group(log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density lprevious_attack ///
mboccup pct_mursi_2012 pct_shafiq_2012 shafiq_sq rabaa sqrt_killed_at_rabaa ///
CPI_pct public_holiday_christian public_holiday_muslim friday sqrt_co_ethnic ///
sqrt_distance_from_north_sinai sqrt_distance_to_gov_centre ///
sqrt_police_strikes)

vce2way mlogit ///
$basic_dv ///
log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density lprevious_attack ///
mboccup pct_mursi_2012 pct_shafiq_2012 shafiq_sq rabaa sqrt_killed_at_rabaa ///
CPI_pct public_holiday_christian public_holiday_muslim friday sqrt_co_ethnic ///
sqrt_distance_from_north_sinai sqrt_distance_to_gov_centre ///
sqrt_police_strikes, ///
cluster(gov_ID adm2_pcode)

predict p2
gen colinear_pattern = 1 if p2 < .145 | p2 > .999990

vce2way mlogit ///
$basic_dv $h1 $h2 $h3 $h4 $controls if colinear_pattern != 1, ///
cluster(gov_ID adm2_pcode)
mlogit, rrr
	
********************************************************************************
*Appendix Table B2 - How varying the lag of recent anti-Christian events predicts the incidence of burnings, beatings, and bombings
********************************************************************************

*2 days
global controls_alt_2 log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density l2previous_attack	

*3 days
global controls_alt_3 log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density l3previous_attack	

*4 days
global controls_alt_4 log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density l4previous_attack		
	
*5 days
global controls_alt_5 log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density l5previous_attack	

*6 days
global controls_alt_6 log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density l6previous_attack	

*7 days
global controls_alt_7 log10christians sqrt_coptic_churches ///
agriculture_pct university_pct ///
ln_population_density l7previous_attack		


vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode) 
mlogit, rrr

vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls_alt_2, cluster(gov_ID adm2_pcode) 
mlogit, rrr

vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls_alt_3, cluster(gov_ID adm2_pcode) 	
mlogit, rrr
	
vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls_alt_4, cluster(gov_ID adm2_pcode) 	
mlogit, rrr

vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls_alt_5, cluster(gov_ID adm2_pcode) 	
mlogit, rrr

vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls_alt_6, cluster(gov_ID adm2_pcode) 	
mlogit, rrr
	
vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls_alt_7, cluster(gov_ID adm2_pcode) 	
mlogit, rrr

********************************************************************************
*Appendix Table B3 - How varying the Rabaa period predicts the incidence of burnings, beatings, and bombings
********************************************************************************

*2 weeks
global h1_alt mboccup pct_mursi_2012 c.pct_shafiq_2012##c.pct_shafiq_2012 rabaa_2weeks sqrt_killed_at_rabaa

*3 weeks
global h1_alt2 mboccup pct_mursi_2012 c.pct_shafiq_2012##c.pct_shafiq_2012 rabaa_3weeks sqrt_killed_at_rabaa

*4 weeks
global h1_alt3 mboccup pct_mursi_2012 c.pct_shafiq_2012##c.pct_shafiq_2012 rabaa_4weeks sqrt_killed_at_rabaa

*8 weeks
global h1_alt4 mboccup pct_mursi_2012 c.pct_shafiq_2012##c.pct_shafiq_2012 rabaa_8weeks sqrt_killed_at_rabaa

*12 weeks
global h1_alt5 mboccup pct_mursi_2012 c.pct_shafiq_2012##c.pct_shafiq_2012 rabaa_12weeks sqrt_killed_at_rabaa


vce2way mlogit $basic_dv $h1 $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode) 
mlogit, rrr

vce2way mlogit $basic_dv $h1_alt $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode) 
mlogit, rrr

vce2way mlogit $basic_dv $h1_alt2 $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode) 
mlogit, rrr

vce2way mlogit $basic_dv $h1_alt3 $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode) 
mlogit, rrr

vce2way mlogit $basic_dv $h1_alt4 $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode) 
mlogit, rrr

vce2way mlogit $basic_dv $h1_alt5 $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode) 
mlogit, rrr


********************************************************************************
*Appendix Table B4 - Predicting anti-Christian violence with dummy DV
********************************************************************************

vce2way logit sectarian_dummy $h1 $h2 $h3 $h4 $controls, cluster(gov_ID adm2_pcode) 
logit, or

log close
